<?php

namespace app\admin\controller;
use app\admin\model\Article;
use app\admin\model\Category;
use app\admin\model\Comment;
use app\admin\model\Goods;
use app\admin\model\Link;
use app\admin\model\Logs;
use app\admin\model\User;
use app\BaseController;
use think\facade\Db;

class Index extends Base
{
    public function index()
    {
        $this->logs('[管理员]主页面视图');
        // 待审核的用户及友联，文章
        $art_review = Db::name('article')->where('status' , 0)->count();
        $link_review = Db::name('link')->where('status' , 0)->count();
        $user_review = Db::name('user')->where('status' , 2)->count();
        // 自建商品和商品库存缺少
        $goodStock = Goods::goodStockNeed();
        return view('index' , ['artReview' => $art_review , 'linkReview' => $link_review , 'userReview' => $user_review , 'goodStock' => $goodStock]);
    }
    // 主页面
    public function main()
    {
        $this->logs('[管理员]主页面');
        $artTime = Article::publishList();
        $userCount = User::count();
        $artCount = Article::count();
        $LinkCount = Link::count();
        $userTime = User::userReg();
        $cateCount = (new Category())->threeCount();
        $ipNum = Logs::whereDay('create_time')->group('ip')->count();
        $base = [
            'os' => php_uname('s') , 'heat' => config('dayHeat.heat'), 'ip' => $ipNum
        ];
        return view(
            'main',
            ['artTime' => $artTime , 'userTime' => $userTime
             , 'userCount' => $userCount, 'artCount' => $artCount,
              'linkCount' => $LinkCount , 'cateCount' => $cateCount ,'base' => $base ]
        );
    }
}
